typedef struct TreeNode TreeNode;

// step 1# 合并两棵二叉树的函数
TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {
    // step 1.1# 如果 t1 为空，直接返回 t2
    if (t1 == NULL) return t2;

    // step 1.2# 如果 t2 为空，直接返回 t1
    if (t2 == NULL) return t1;

    // step 1.3# 合并根节点的值（中）
    t1->val += t2->val;

    // step 1.4# 递归合并左子树（左）
    t1->left = mergeTrees(t1->left, t2->left);

    // step 1.5# 递归合并右子树（右）
    t1->right = mergeTrees(t1->right, t2->right);

    // step 1.6# 返回合并后的根节点
    return t1;
}

/* 1. 20250421 */
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
/*
    1. 如果 treeA 空，则返回 treeB
    2. 如果 treeB 空，则返回 treeA
    3. 否则 把 A B 的值相加到 treeA
    4. 递归左子树
    5. 递归右子树
    6. 最后返回 tree A

*/
typedef struct TreeNode TreeNode;

TreeNode *merge(TreeNode *treeA, TreeNode *treeB) {
    if (treeA == NULL) return treeB;
    if (treeB == NULL) return treeA;

    treeA->val += treeB->val;

    treeA->left = merge(treeA->left, treeB->left);
    treeA->right = merge(treeA->right, treeB->right);

    return treeA;
}

struct TreeNode* mergeTrees(struct TreeNode* root1, struct TreeNode* root2) {
    return merge(root1, root2);
}